package com.pengshun.modules.api.transport.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.coal.validator.Third;
import com.pengshun.modules.api.transport.dto.FreightSettlementDto;
import com.pengshun.modules.api.transport.dto.TransportAbnormalOperationDto;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.api.transport.service.FreightSettlementService;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.FreightSettlementPrice;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "结算管理",position = 0)
@RequestMapping("/api/settlement")
public class FreightSettlementController {

    private  final FreightSettlementService freightSettlementService;

    @ApiOperation(value = "司机结算列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1待结算、2已结算", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/driver-list")
    @Authorization
    @ApiOperationSupport(order = 10)
    public BaseResult driverList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = freightSettlementService.driverList(para);
        return res;
    }

    @ApiOperation(value = "运输公司结算列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1待结算、2已结算", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/transport-list")
    @Authorization
    @ApiOperationSupport(order = 20)
    public BaseResult transportList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = freightSettlementService.transportList(para);
        return res;
    }

    @ApiOperation(value = "司机异常运单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1待处理，2处理中，3已处理", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @ApiOperationSupport(order = 30)
    @GetMapping(value = "/driver-abnormal-list")
    @Authorization
    public BaseResult driverAbnormalList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = freightSettlementService.driverAbnormalList(para);
        return res;
    }

    @ApiOperation(value = "运输公司异常运单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1待处理，2已处理", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/transport-abnormal-list")
    @Authorization
    @ApiOperationSupport(order = 40)
    public BaseResult transportAbnormalList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = freightSettlementService.transportAbnormalList(para);
        return res;
    }
    @ApiOperation(value = "司机异常申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "备注", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "photos.[0].photo", value = "图片地址", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @ApiOperationSupport(order =50)
    @PostMapping(value = "/driver-abnormal-apply")
    @Authorization
    public BaseResult driverAbnormalApply(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) TransportAbnormalOperationDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUserName(user.getName());
        BaseResult res = freightSettlementService.driverAbnormalApply(para);
        return res;
    }
    @ApiOperation(value = "异常申请详情、重新提交查询用")
    @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query")
    @ApiOperationSupport(order =60)
    @GetMapping(value = "/abnormal-apply-detil")
    public BaseResult AbnormalApplyDetil(@ApiIgnore @Validated(value = {Second.class}) TransportAbnormalOperationDto para) throws Exception {
        BaseResult res = freightSettlementService.AbnormalApplyDetil(para.getFreightSettlementId());
        return res;
    }
    @ApiOperation(value = "异常申请处理同意 拒绝")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "备注", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 2处理完成 3处理失败", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @ApiOperationSupport(order =70)
    @GetMapping(value = "/abnormal-dispose")
    @Authorization
    public BaseResult AbnormalDispose(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Third.class}) TransportAbnormalOperationDto para) throws Exception {
        para.setUserId(user.getId());
        para.setUserName(user.getName());
        BaseResult res = freightSettlementService.AbnormalDispose(para);
        return res;
    }

    @ApiOperation(value = "异常详情")
    @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query")
    @ApiOperationSupport(order =80)
    @GetMapping(value = "/abnormal-detil")
    public BaseResult AbnormalDetil( @ApiIgnore @Validated(value = {Second.class}) TransportAbnormalOperationDto para) throws Exception {
        BaseResult res = freightSettlementService.AbnormalDetil(para.getFreightSettlementId());
        return res;
    }

//    @ApiOperation(value = "运费结算油卡现金调整")
//    @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query")
//    @ApiOperationSupport(order =80)
//    @PostMapping(value = "/update-fee")
//    public BaseResult updateFee( @ApiIgnore @Validated(value = {Second.class}) FreightSettlementDto para) throws Exception {
//        BaseResult res = freightSettlementService.updateFee(para.getFreightSettlementId());
//        return res;
//    }






    @ApiOperation(value = "货运结算详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
    })
    @ApiOperationSupport(order = 90)
    @GetMapping(value = "/transport-detil")
    public BaseResult transportDetil(  @ApiIgnore @Validated(value = {Fourth.class}) FreightSettlementDto para) throws Exception {
        BaseResult res = freightSettlementService.transportDetil(para.getFreightSettlementId());
        return res;
    }
    @ApiOperation(value = "货运结算状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportTakeCarriageId", value = "接单id", dataType = "int", required = true, paramType = "query"),
    })
    @ApiOperationSupport(order = 90)
    @GetMapping(value = "/transport-status")
    public BaseResult transportStatus(  @ApiIgnore @Validated(value = {Second.class}) FreightSettlementDto para) throws Exception {
        BaseResult res = freightSettlementService.transportStatus(para.getTransportTakeCarriageId());
        return res;
    }

    @ApiOperation(value = "司机运费结算添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "transportTakeCarriageId", value = "运输接单id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportId", value = "货运信息id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "有了传 没有不传 订单id", dataType = "int",    paramType = "query"),
            @ApiImplicitParam(name = "settlementAmount", value = "结算总金额", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "mineSendNum", value = "矿发吨位", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "realNum", value = "实收吨位", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "diffNum", value = "差异吨位", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "结算总金额", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "urls", value = "图片地址 用逗号隔开", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportTakeNo", value = "接单号", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "merchantId", value = "商户id", dataType = "string", required = true, paramType = "query"),

    })
    @PostMapping(value = "/save")
    @Authorization
    @NoRepeatSubmit
    @ApiOperationSupport(order = 100)
    public BaseResult save( @ApiIgnore @CurrUserInfo User user,  @ApiIgnore @Validated(value = {First.class}) FreightSettlementDto para) throws Exception {
        para.setApplyUserId(user.getId());
        BaseResult res = freightSettlementService.save(para);
        return res;
    }

    @ApiOperation(value = "司机货运结算修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "settlementAmount", value = "结算总金额", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "mineSendNum", value = "矿发吨位", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "realNum", value = "实收吨位", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "diffNum", value = "差异吨位", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "结算总金额", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "urls", value = "图片地址 用逗号隔开", dataType = "string", required = true, paramType = "query"),

    })
    @PostMapping(value = "/update")
    @Authorization
    @NoRepeatSubmit
    @ApiOperationSupport(order = 100)
    public BaseResult update( @ApiIgnore @Validated(value = {Fourth.class}) FreightSettlementDto para) throws Exception {
        BaseResult res = freightSettlementService.update(para);
        return res;
    }


    @ApiOperation(value = "货运结算退回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "casue", value = "退回原因", dataType = "string", required = true, paramType = "query"),

    })
    @PostMapping(value = "/back")
    @Authorization
    @ApiOperationSupport(order = 110)
    public BaseResult back( @ApiIgnore @CurrUserInfo User user,  @ApiIgnore @Validated(value = {Fourth.class}) FreightSettlementDto para) throws Exception {
        BaseResult res = freightSettlementService.back(para);
        return res;
    }

    @ApiOperation(value = "货运结算费用修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "newPrice", value = "煤价", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "newFreight", value = "运费", dataType = "double",  paramType = "query"),

    })
    @PostMapping(value = "/update-price")
    @Authorization
    @ApiOperationSupport(order = 110)
    public BaseResult updatePrice( @ApiIgnore @CurrUserInfo User user,  @ApiIgnore @Validated(value = {Fourth.class}) FreightSettlementPrice para) throws Exception {
        para.setUpdateBy(user.getName());
        BaseResult res = freightSettlementService.updatePrice(para);
        return res;
    }

    @ApiOperation(value = "运输公司确认司机运费  自己支付运费")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "payWay", value = "支付方式(1余额，2微信)", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "payPass", value = "支付密码", dataType = "string", paramType = "query"),

    })
    @PostMapping(value = "/pay")
    @Authorization
    @NoRepeatSubmit
    @ApiOperationSupport(order = 120)
    public BaseResult pay( @ApiIgnore @CurrUserInfo User user,  @ApiIgnore @Validated(value = {Fourth.class}) FreightSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = freightSettlementService.pay(para);
        return res;
    }

    @ApiOperation(value = "运输公司确认司机运费  平台支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "freightSettlementId", value = "结算id", dataType = "int", required = true, paramType = "query"),

    })
    @PostMapping(value = "/sure")
    @Authorization
    @NoRepeatSubmit
    @ApiOperationSupport(order = 130)
    public BaseResult sure( @ApiIgnore @CurrUserInfo User user,  @ApiIgnore @Validated(value = {Fourth.class}) FreightSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = freightSettlementService.sure(para);
        return res;
    }

}
